package com.fairytask.ui
{
	import com.fairytask.engine.components.button.Button;
	import com.fairytask.engine.components.clip.Clip;
	import com.fairytask.engine.components.text.Label;
	import com.fairytask.engine.define.ResConfig;
	import com.fairytask.engine.utils.DateFormatter;
	import com.fairytask.resource.StaticIni;
	import com.fairytask.ui.base.FrameUI;
	
	import flash.events.MouseEvent;
	
	/**
	 * 邮件基本信息窗口 
	 * @author pangj
	 * 
	 */
	public class MailInfoUI extends FrameUI
	{
		private var readed    :String = ResConfig.pngResPath+"mail_readed.jpg";//已读邮件图标
		private var unRead    :String = ResConfig.pngResPath+"mail_unRead.jpg";//未读邮件图标
		
		public var mailImg    :Clip;   //邮件图标
		public var mailTitle  :Label;  //邮件标题标签
		public var getTime    :Label;  //发件时间标签
		public var remainTime :Label;  //剩余时间标签
		public var deleteBtn  :Button; //删除按钮
		private var mailID    :int;    //邮件编号 key
	
		public function MailInfoUI(mailID:int,popUI:Boolean=true)
		{
			super(popUI);
			this.mailID = mailID;
			windowBG.addEventListener(MouseEvent.CLICK,onChoose);
		}
		/**
		 * 选中邮件
		 * 
		 */
		public function onChoose(e:MouseEvent):void
		{
			MailFrameUI.getInstance().sendDetails(e,mailID,e.target.toString()=="[object Sprite]");
			mailImg.source = readed;
		}
		
		/**
		 *设置邮件图标
		 * @param isRead 是否已读
		 */
		public function set MailImg(isRead:int):void
		{
			mailImg.source = isRead?readed:unRead;
		}
		/**
		 * 设置邮件标题
		 * @param value
		 */
		public function set MailTitle(value:String):void
		{
			mailTitle.htmlStr=value
		}
		/**
		 * 设置发件时间 并 计算剩余时间 
		 * @param value
		 */
		public function set GetTime(value:String):void
		{
			var sendTime:Number = uint(value)*1000;
			//设置发送时间
			getTime.htmlStr = DateFormatter.DateFormat(new Date(sendTime),"YYYY-MM-DD");
			//设置剩余时间
			var keepDay:int = 30;//保存时间：默认30天
			var arr:Array = new Array;
			arr[0] = String((new Date(sendTime+(keepDay-1)*86400000-(new Date).time)).date);//86400000 = 24*60*60*1000

			remainTime.htmlStr = StaticIni.getSwfLangStrVar("1000000202",arr);
		}
	}
}